import request from '@/utils/request'
//1.请求一级分类列表
// 返回值类型
export interface Category1ReturnItemType {
  id: number,
  name: string
}
export type Category1ReturnType = Category1ReturnItemType[]
export const requestCategoryList1 = () => {
  return request.get<any, Category1ReturnType>('/admin/product/getCategory1')
}


//2.请求二级分类列表

export interface Category2ReturnItemType extends Category1ReturnItemType {
  category1Id: number
}
export type Category2ReturnType = Category2ReturnItemType[]


export const requestCategoryList2 = (category1Id: number) => {
  return request.get<any, Category2ReturnType>(`/admin/product/getCategory2/${category1Id}`)
}

//3.请求三级分类列表
export const requestCategoryList3 = (category2Id: number) => {
  return request.get<any, Category2ReturnType>(`/admin/product/getCategory3/${category2Id}`)
}

//某个属性内某个属性值的类型
export interface attrValueListType {
  id?: number;
  valueName: string;
  attrId: number;
}

//某个属性的类型
export interface attrListItemType {
  id?: number;
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  attrValueList: attrValueListType[];
}

//商品基础属性返回值类型
export type attrListType = attrListItemType[]


//4.获取商品基础属性
export const requestattrList = (category1Id: number, category2Id: number, category3Id: number) => {
  return request.get<any, attrListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}


//5.删除商品基础属性
export const requestDeleteAttr = (attrId:number)=>{
  return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}

//6.更新或新增属性
export const requestUpdateOrAddAttr = (newAttr:attrListItemType)=>{
  return request.post<any,null>('/admin/product/saveAttrInfo',newAttr)
}


